﻿var fbLoginStatus = '';

/* facebook stuff */
window.fbAsyncInit = function () {
    FB.init({
        appId: '822301227802041',
        xfbml: true,
        version: 'v2.1'
    });

    if (typeof OnFBInit == 'function')
        OnFBInit();
};

function InitFB() {
    var d = document, s = 'script', id = 'facebook-jssdk';
    var js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id)) { return; }
    js = d.createElement(s); js.id = id;
    js.src = "//connect.facebook.net/nl_NL/sdk.js";
    fjs.parentNode.insertBefore(js, fjs);
}

function GetFbLoginStatus() {
	FB.getLoginStatus(function (response) {
		fbLoginStatus = response.status;
	});
}

function fbPost(msgs) {
	GetFbLoginStatus();

	window.setTimeout(function () {
		if (fbLoginStatus === 'connected')
			fbPostMulti(msgs);
		else if (fbLoginStatus === 'not_authorized') {
			FB.login(function (response) {
				if (response.authResponse) {
					fbPostMulti(msgs);
				}
			}, { scope: 'publish_actions' });
			
		}
	}, 500);
}

function fbPostMulti(msgs) {
	$.each(msgs, function (index, value) {
		fbPostSingle(value);
	});
}

function fbPostSingle(msg) {
	FB.api('/me/feed', 'post', { message: msg, link: 'http://www.gollie.nl' });
}
